package wangguolongTest;

import android.app.LocalActivityManager;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.example.znbk.znbklibrary.base.BaseActivity;
import com.lancoo.znbkxx.R;

import java.util.ArrayList;
import java.util.List;

public class TestMainActivity extends BaseActivity {

    private List<View> mViews = new ArrayList<View>();
    private LocalActivityManager manager;
    private Intent intentMain, intentCircle, intentMy;


    @Override
    protected int setLayout() {
        return R.layout.activity_testmain;
    }

    @Override
    protected void initView() {

        ViewPager viewPager =  findViewById(R.id.vp_testmain);
        intentMain = new Intent(this, TestOneActivity.class);
        View tab01 = manager.startActivity("viewID1", intentMain).getDecorView();
        intentCircle = new Intent(this, TestTwoActivity.class);
        View tab02 = manager.startActivity("viewID2", intentCircle).getDecorView();
        intentMy = new Intent(this, TestThreeActivity.class);
        View tab03 = manager.startActivity("viewID3", intentMy).getDecorView();
        mViews.add(tab01);//将页面添加到View集合
        mViews.add(tab02);
        mViews.add(tab03);
        PagerAdapter pagerAdapter = new PagerAdapter() {
            @Override
            public boolean isViewFromObject(View arg0, Object arg1) {
                // TODO Auto-generated method stub
                return arg0 == arg1;
            }
            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return mViews.size();
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                // TODO Auto-generated method stub
                container.removeView(mViews.get(position));
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                // TODO Auto-generated method stub
                container.addView(mViews.get(position));
                return mViews.get(position);
            }
        };
        viewPager.setAdapter(pagerAdapter);// 配置适配器

    }

}